<%@ Page Language="C#" Debug="true" %>
<%@ Import namespace="System.Net" %>
<%@ Import namespace="System.Collections.Generic" %>
<%@ Import namespace="Utils" %>
<%

string token = (string)Session["token"];

if(String.IsNullOrEmpty(token))
{
	token = ServiceUtil.getAccessToken();

	Session["token"] = token;
}

string usersJson = "";

try
{
	usersJson = ServiceUtil.getUsersJson(token);
}
catch(Exception ex)
{
	//Response.Write(ex.Message);
	if(ex.Message.ToLower().IndexOf("unauth") >= 0)
	{
		//refresh the access token
		token = ServiceUtil.getAccessToken();

		Session["token"] = token;

		usersJson = ServiceUtil.getUsersJson(token);
	}
}

Response.ContentType = "application/json";
Response.Write(usersJson);
%>